<?php

namespace App\Admin\Controllers;

use App\Models\Recharge;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class RechargesController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '充值管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Recharge);
        $grid->model()->orderBy('created_at','desc');
        $grid->column('id', __('Id'));
        $grid->column('user.username', __('用户名'));
        $grid->column('amount', __('充值金额'));
        $grid->column('pay_type', __('充值类型'));
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
        $grid->column('pay_at', __('支付时间'));
        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.status')[$status];
        });
        $grid->column('pay_status', __('支付状态'))->display(function ($status) {
            return config('conf.pay_status')[$status];
        });
        $grid->column('no', __('订单号'));
        $grid->disableCreateButton();
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Recharge::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('amount', __('Amount'));
        $show->field('pay_type', __('Pay type'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('pay_at', __('Pay at'));
        $show->field('status', __('Status'));
        $show->field('pay_status', __('Pay status'));
        $show->field('no', __('No'));
        $show->field('restful', __('Restful'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Recharge);

        $form->number('user_id', __('用户名'));
        $form->decimal('amount', __('充值金额'));
        $form->text('pay_type', __('支付类型'));
        $form->datetime('pay_at', __('支付时间'))->default(date('Y-m-d H:i:s'));
        $form->display('status', __('状态'))->options(config('conf.status'));
        $form->display('pay_status', __('支付状态'))->options(config('conf.pay_status'));
        $form->text('no', __('订单号'));

        return $form;
    }
}
